package com.hadwinling.socket;

import java.io.OutputStream;
import java.net.Socket;

/**
 * 基于TCP协议，客户端向服务端发送消息
 * @author HadwinLing
 * @version V1.0
 * @Package com.hadwinling.socket
 * @date 2020/11/14 10:26
 */
public class ClientTCP {
    public static void main(String[] args) {
        //
        try(Socket socket=new Socket("localhost", 8888); OutputStream os=socket.getOutputStream()){
            System.out.println("客户端启动成功，开始发送数据");
            //发送消息给服务端
            os.write("hello".getBytes());

        }catch(Exception e) {
            e.printStackTrace();
        }
    }
}
